
public class Stacker {

	public static void main(String[] args) throws Exception {
		TwoStacks one = new TwoStacks(200);
		TwoStacks two = new TwoStacks(400);
		TwoStacks three = new TwoStacks(800);
		TwoStacks four = new TwoStacks(1600);

		//int i=0;
		long start = System.currentTimeMillis();
		try{
			while(true){
				du(one);
			//	i++;
				//System.out.println(i+" FIRST "+ one.firstStack + " TWO"+ one.secondStack);
			}
		}
		catch(StackColissionException e){
			System.out.println(System.currentTimeMillis()-start+"ms "+e.getMessage());
		}
		start = System.currentTimeMillis();
		try{
			while(true){
				du(two);
				//i++;
				//System.out.println(i+" FIRST "+ one.firstStack + " TWO"+ one.secondStack);
			}
		}
		catch(StackColissionException e){
			System.out.println(System.currentTimeMillis()-start+"ms "+e.getMessage());
		}
		start = System.currentTimeMillis();
		try{
			while(true){
				du(three);
				//i++;
				//System.out.println(i+" FIRST "+ one.firstStack + " TWO"+ one.secondStack);
			}
		}
		catch(StackColissionException e){
			System.out.println(System.currentTimeMillis()-start+"ms "+e.getMessage());
		}
		start = System.currentTimeMillis();
		try{
			while(true){
				du(four);
				//i++;
				//System.out.println(i+" FIRST "+ one.firstStack + " TWO"+ one.secondStack);
			}
		}
		catch(StackColissionException e){
			System.out.println(System.currentTimeMillis()-start+"ms "+e.getMessage());
		}
	}
	
	public static void du (TwoStacks i) throws Exception{
		double q = Math.random()*10;
		double p = Math.random()*10;
		if (p < 5)
			if (q < 5)
				i.popOne();
			else
				i.pushOne(Math.random());
		else
			if (q < 5)
				i.popTwo();
			else
				i.pushTow(Math.random());
			
		
	}
}
